<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 
* Module default for frontpage
* @author DANG DINH HUNG
*
*/
class User extends Public_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('user_m'); 
		$this->load->library('module_helper');
	
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/md5.js"."' ></script>");
		$this->template->append_metadata("<script src='".site_url()."addons/default/themes/sbx/js/user.js"."' ></script>");
	}
	
	public function index()
	{
		$this->user_m->_redirectUser();
	}	
	
	function signin(){
		$this->user_m->_redirectUser();
		$this->data->items = $this->user_m->signin();
		
		$this->template
			->build('signin', $this->data);			
	}
	
	function submit(){
		$this->user_m->_redirectUser();
		
		$this->data->items = $this->user_m->submit();
	}
	
	function signin_notify(){
		$this->user_m->_redirectUser();
		
		$this->data = null;
		$this->template
			->build('signin_notify', $this->data);	
	}
	
	function login(){
		$this->user_m->_redirectUser();
		
		$this->data = null;
		$this->template
			->build('login', $this->data);	
	}
	
	function submit_login(){
		$this->user_m->_redirectUser();
		$this->data = $this->user_m->submit_login();
	}
	
	function forgot_password(){
		$this->user_m->_redirectUser();
		$this->data->items = array('captcha'=>$this->user_m->_createNewCaptcha());
		
		$this->template
			->build('forgot_password', $this->data);
	}
	
	function forgot_password_notity(){
		$this->user_m->_redirectUser();
	
		$this->data = null;
		$this->template
			->build('forgot_password_notity', $this->data);
	}
	
	function submit_email_forgot(){
		$this->user_m->_redirectUser();
		$this->user_m->submit_email_forgot();
	}
	
	function regenerate_password(){
		$this->user_m->_redirectUser();
		
		$this->data->items = $this->user_m->regenerate_password();
		$this->template
			->build('regenerate_password', $this->data);
	}
	
	function confirm(){
		$this->user_m->_redirectUser();
		
		$this->data->items = $this->user_m->confirm();
		$this->template
			->build('confirm', $this->data);
	}
	
	function logout(){
		unset($_SESSION['user']);
		redirect(site_url());
	}
	
	function crontab(){
		//$USER = clone_( $this->user_entity->init('id',5) );
		
		//$USER2 = $this->user_entity->init('id',15);
		
		//echo $USER->getEmail().'-'.$USER2->getEmail();
		//$arr =unserialize($USER->getRevision());
		// print_r($arr);
		//$this->load->library('crontab_email');
		//$this->crontab_email->cronUpdate('123','_sendEmailToUser_confirm', '5', "".time()."" );
		//$this->crontab_email->cronExec('123');
		$this->crontab_email->cronExec();
		exit();
	}
	
	function confirm2(){
		$this->load->library('email_sender');
		$SHOW = $this->show_entity->init('ref_no',$_GET['show_ref']);
		if($SHOW->makescrid() != $_GET['scrid']){
			show_404();exit();
		}
		$SELLER = $this->user_entity->init('id', $SHOW->getUserCreatedId() );
		
		$body = "Seller information:<br/>";
		$body .= "Seller email: ".$SELLER->getEmail() ."<br/>";
		$body .= "Show information: <br/>";
		$body .= "Show ref: ".$SHOW->getRefNo() ."<br/>";
		
		$this->email_sender->setFromEmail(Settings_class::get('server_email'));
		$this->email_sender->setToEmail(Settings_class::get('contact_email'));
		$this->email_sender->setSubject("Seller confirmed escrow release.");
		$this->email_sender->setBody( $body );
		$this->email_sender->sendEmail();
		
		$this->template
			->build('confirm_escrow_release', $this->data =null);
	}
}